import axios from 'axios'

// 发帖
export function publish (postInfo) {
    return axios.post(`post`, postInfo)
}

// 删帖
export function deletePost (postId) {
    return axios.delete(`post/${postId}`)
}

// 根据帖子Id获取帖子
export function getById (postId) {
    return axios.get(`post/one/${postId}`)
}

// 分页获取当前用户的贴子
export function pageCurrentPosts (pageInfo) {
    return axios.get(`post/${pageInfo.page}/${pageInfo.size}`)
}

// 分页获取用户的帖子
export function pageAuthorPosts (queryInfo) {
    return axios.get(`post/${queryInfo.authorId}/${queryInfo.page}/${queryInfo.size}`)
}

// 分页获取区域帖子
export function pageAreaPost (queryInfo) {
    return axios.get(`post/list/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            area: queryInfo.area,
            type: queryInfo.type,
            asc: queryInfo.asc,
            desc: queryInfo.desc
        }
    })
}

// 推荐
export function recommend () {
    return axios.get(`post/recommend`)
}

// 获取当前用户收藏的帖子
export function currentCollectPosts () {
    return axios.get(`post/collect`)
}

// 收藏帖子
export function collectPost (postId) {
    return axios.post(`post/collect/${postId}`)
}

// 取消收藏帖子
export function removeCollectPost (postId) {
    return axios.delete(`post/collect/${postId}`)
}

// 设置帖子标签
export function setPostLabels (updateInfo) {
    return axios.put(`post/label/${updateInfo.postId}`,
        { params: { labelIds: updateInfo.labelIds } })
}

// 获得推送
export function push () {
    return axios.get(`post/push`)
}

// 搜索
export function searchContent (searchInfo) {
    return axios.get(`search/${searchInfo.page}/${searchInfo.size}`,
        { params: { content: searchInfo.content } })
}
